var userinfo;
server.getUserInfo(function (res) {
    userinfo=res;
    $("#userhead").attr('src',userinfo.headimgurl);
    $("#username").text(userinfo.nickname);
    console.log("vip buy..")
    console.log(userinfo)
    if(res.memberLevel==0){
        $("#vipex").text('您的会员权益已过期 >');
        $("#vipbtn").html('<div class="buymember-right-button" onclick="submitorder()">\n' +
            '                            <label>立即开通</label>\n' +
            '                        </div>');
    }else{
        $("#vipex").text('您已经是玄集的尊贵会员');
    }

});

//获取vip开通价格
server.req('wechat/comm/vipprice',{},function (res) {
    // console.log(res)
    $("#vipprice").text(res.data);
})
//下单
function submitorder(){
    var  obj ;
    obj={};
    var serviceType= $("#serviceType").val();
    obj=$("#vipbuy_frm_main").serializeObject();


    // var teacherid = server.getQueryString("teachid");

    // obj.teacherId=teacherid;
    var item= {};
    obj.itemList=[];

    if(serviceType=="3") {
        item = {
            itemType: obj.serviceType,
            itemName: obj.description,
            description: obj.description,
            birthId: obj.birthid,
            openQuestions: (obj.publicask && obj.publicask == "on") ? 1 : 0
        };
    }else if(serviceType=="1")  {
        item = {
            itemType: obj.serviceType,
            itemId:obj.service

        };
    }else if(serviceType=="2")  {
        item = {
            itemType: obj.serviceType,
            itemId:obj.serviceId,
            birthId: obj.birthid
        };
    }else if(serviceType=="5")  {
        item = {
            itemType: obj.serviceType,
            itemId:obj.serviceId

        };
    }
    //  itemList.push(item);
    obj.itemList.push(item);
    console.log(obj)
    server.req("wechat/order/createOrder",obj,function (e){
        console.log(e);
        if(e.code==0){
            server.setCache("orderInfo",JSON.stringify(e.data));
            server.loadindex('page/order/submitorder/submitorder',"",true);
        }else{
            pop_up(e.msg)
        }
    },null,"POST")

};